﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DoAnASP;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Web.Configuration;

namespace DoAnASP
{
    public class DAO_ThongTinSP
    {
        DAO_dataProvider kn = new DAO_dataProvider();
        public void Capnhat_ThongTinSp(DTO_ThongTinSP tt)
        {
            kn.ChuoiKetNoi();
            kn.Open_Connection();

            string sql2 = "Update ThongTinSP set CongNgheCPU=@CongNgheCPU,MaSP=@MaSP, LoaiCPU=@LoaiCPU, DungLuongRAM=@DungLuongRAM, DungLuongODia=@DungLuongODia, KichThuocMH=@KichThuocMH, CardDoHoa=@CardDoHoa, KetNoiMang=@KetNoiMang,TichHop=@TichHop, HeDieuHanh=@HeDieuHanh, TrongLuong=@TrongLuong, ThongTinPin=@ThongTinPin,KhuyenMai=@KhuyenMai,XuatXu=@XuatXu,ThoiGianBH=@ThoiGianBH,Keyboard=@Keyboard where MaSP=@MaSP";
            
            SqlCommand cmd = new SqlCommand(sql2, kn.conn);

            cmd.Parameters.Add("@CongNgheCPU", SqlDbType.NVarChar);
            cmd.Parameters.Add("@MaSP", SqlDbType.Int);
            cmd.Parameters.Add("@LoaiCPU", SqlDbType.NVarChar);
            cmd.Parameters.Add("@DungLuongRAM", SqlDbType.NVarChar);
            cmd.Parameters.Add("@DungLuongODia", SqlDbType.NVarChar);
            cmd.Parameters.Add("@KichThuocMH", SqlDbType.NVarChar);
            cmd.Parameters.Add("@CardDoHoa", SqlDbType.NVarChar);
            cmd.Parameters.Add("@KetNoiMang", SqlDbType.NVarChar);
            cmd.Parameters.Add("@TichHop", SqlDbType.NVarChar);
            cmd.Parameters.Add("@HeDieuHanh", SqlDbType.NVarChar);
            cmd.Parameters.Add("@TrongLuong", SqlDbType.NVarChar);
            cmd.Parameters.Add("@ThongTinPin", SqlDbType.NVarChar);
            cmd.Parameters.Add("@KhuyenMai", SqlDbType.NVarChar);
            cmd.Parameters.Add("@XuatXu", SqlDbType.NVarChar);
            cmd.Parameters.Add("@ThoiGianBH", SqlDbType.NVarChar);
            cmd.Parameters.Add("@Keyboard", SqlDbType.NVarChar);
            //cmd.Parameters.Add("@ImageSP", SqlDbType.NVarChar);


            cmd.Parameters["@CongNgheCPU"].Value = tt.CongngheCPU;
            cmd.Parameters["@MaSP"].Value = tt.MaSP;
            cmd.Parameters["@LoaiCPU"].Value = tt.LoaiCPU;
            cmd.Parameters["@DungLuongRAM"].Value = tt.DungLuongRAM;
            cmd.Parameters["@DungLuongODia"].Value = tt.DuongLuongDia;
            cmd.Parameters["@KichThuocMH"].Value = tt.KichThuocMH;
            cmd.Parameters["@CardDoHoa"].Value = tt.CarDoHoa;
            cmd.Parameters["@KetNoiMang"].Value = tt.KetNoiMang;
            cmd.Parameters["@TichHop"].Value = tt.TichHop;
            cmd.Parameters["@HeDieuHanh"].Value = tt.HeDieuHanh;
            cmd.Parameters["@TrongLuong"].Value = tt.TrongLuong;
            cmd.Parameters["@ThongTinPin"].Value = tt.ThongTinPin;
            cmd.Parameters["@KhuyenMai"].Value = tt.KhuyenMai;
            cmd.Parameters["@XuatXu"].Value = tt.XuatXu;
            cmd.Parameters["@ThoiGianBH"].Value = tt.ThoiGianSD;
            cmd.Parameters["@Keyboard"].Value = tt.KeyBoard;


            cmd.ExecuteNonQuery();
            kn.Close_Connection();
        }

        public DataTable TTSP_masp(int masp)
        { 
            kn.ChuoiKetNoi();
            kn.Open_Connection();

            string sql2 = "Select *from ThongTinSP where MaSP=@MaSP";
            SqlCommand cmd = new SqlCommand(sql2,kn.conn);
            cmd.Parameters.Add("@MaSP", SqlDbType.Int).Value = masp;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            kn.Close_Connection();
            return dt;
        }

        public DataTable ChiTiet_SP (int masp)
        {
            kn.ChuoiKetNoi();
            kn.Open_Connection();

            string sql2 = "Select * from SanPham, ThongTinSP where SanPham.MaSP=@MaSP";
            SqlCommand cmd = new SqlCommand(sql2, kn.conn);
            cmd.Parameters.Add("@MaSP", SqlDbType.Int).Value = masp;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            kn.Close_Connection();
            return dt;
        }
    }
}
